import java.net.*;
import java.io.*;
public class Urlcontent  {

	/**Author:Savita
	 * Feb 05,2009
	 * This program returns content of a web page.
	 **/
	private Object content=null;
	private String type;
	private int length;
	private java.awt.Image image;
	private String html;
	private int getcon;
	public Urlcontent(String urlstring)throws MalformedURLException, IOException
	{
		URL url=new URL(urlstring);
		URLConnection ucon=url.openConnection();
		HttpURLConnection con=(HttpURLConnection)ucon;
		con.setConnectTimeout( 10000 );
		con.setReadTimeout( 10000 );
		con.setInstanceFollowRedirects( true );
		con.setRequestProperty( "User-agent", "spider" );
		con.connect();
		length=con.getContentLength();
        content=con.getContent();
        type  = con.getContentType();
	}
	public int getcontent(){
        if ( type.equals( "text/html" ) )
        {
             html = (String)content;
             getcon=1;
             
         }
         else if( type.startsWith( "image" ) && content instanceof java.awt.Image )
         	{
         	    image = (java.awt.Image)content;
         	    getcon=2;
         	    
         	}
        
         else{
         		getcon=0;
         }
        return getcon;
               
     }
	public Object getContent() {
		return content;
	}
	public void setContent(Object content) {
		this.content = content;
	}
	public int getLength() {
		return length;
	}
	public void setLength(int length) {
		this.length = length;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getHtml() {
		return html;
	}
	public void setHtml(String html) {
		this.html = html;
	}
	public java.awt.Image getImage() {
		return image;
	}
	public void setImage(java.awt.Image image) {
		this.image = image;
	}
	
	
	
}
